package com.satan.novel.home.service.impl;

import com.alibaba.nacos.client.naming.utils.CollectionUtils;
import com.satan.novel.common.resp.RestResp;
import com.satan.novel.home.dto.resp.HomeBookRespDto;
import com.satan.novel.home.dto.resp.HomeFriendLinkRespDto;
import com.satan.novel.home.manager.cache.FriendLinkCacheManager;
import com.satan.novel.home.manager.cache.HomeBookCacheManager;
import com.satan.novel.home.service.HomeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Demon
 * @Date: 2024/1/21 19:27
 * @Description: 首页模块 服务实现类
 **/
@Service
@RequiredArgsConstructor
public class HomeServiceImpl implements HomeService {
    private final HomeBookCacheManager homeBookCacheManager;

    private final FriendLinkCacheManager friendLinkCacheManager;

    @Override
    public RestResp<List<HomeBookRespDto>> listHomeBooks() {
        List<HomeBookRespDto> list = homeBookCacheManager.listHomeBooks();
        if (CollectionUtils.isEmpty(list)) {
            homeBookCacheManager.evictCache();
        }
        return RestResp.ok(list);
    }

    @Override
    public RestResp<List<HomeFriendLinkRespDto>> listHomeFriendLinks() {
        return RestResp.ok(friendLinkCacheManager.listFriendLinks());
    }
}
